/**
 * Copyright © 2011 looty - Textoo
 * @link http://www.textoo.org
 * @link http://code.google.com/p/textoo/
 * @author lab9 - Bertrand Larrieu
 * @mail lab9.fr@gmail.com
 * @version 2.0
 */

package org.looty.textoo.render 
{
	import flash.geom.*;
	import flash.text.*;
	import org.looty.core.textoo.format.*;
	import org.looty.textoo.font.*;

	public class TextFieldLetter extends TextField implements ILetter
	{
		
		private var _position		:Point;
		
		public function TextFieldLetter()
		{
			
		}
		
		public function construct(character:String, bounds:Rectangle, props:TextooProps, textFormat:TextFormat):void
		{
			selectable = false;
			antiAliasType = AntiAliasType.ADVANCED;
			gridFitType = GridFitType.PIXEL;
			autoSize = TextFieldAutoSize.LEFT;		
			sharpness = props.sharpness;
			thickness = props.thickness;
			
			if (!props.embedFonts && props.useDeviceFonts) embedFonts = FontUtils.hasGlyphs(character, textFormat);
			else embedFonts = props.embedFonts;
			
			text = character;
			setTextFormat(textFormat);
			autoSize = TextFieldAutoSize.NONE;
			width += 2;
			
			var offset:Rectangle = getCharBoundaries(0);
			if (offset == null) offset = new Rectangle(2, 2, bounds.width, bounds.height);
			
			_position = new Point(bounds.x - offset.x, bounds.y - offset.y);
			x = _position.x;
			y = _position.y;
		}
		
		public function get position():Point 
		{
			return _position;
		}
		
	}

}